<?php 
/**
 * Trieda databazy (Singleton)
 * @author Tomas Srna
 * @package bakalarka
 */

class Db extends Singleton
{
	protected $pdo = NULL;
	
	protected function __construct() {

		$this->pdo = new PDO(
			sprintf("mysql:host=%s;dbname=%s",
			Config::$dbHost,
			Config::$dbDatabase),
			Config::$dbUsername,
			Config::$dbPassword
		);
		
		/**
		 * Chceme vynimky, inak je peklo dostat z toho chybu
		 */
		$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	} 
	
	/**
	 * Interceptor pre transparentnu komunikaciu s nizsou vrstvou
	 */
	public function __call($name, $vars)
	{
		if(is_callable(array($this->pdo, $name)))
			return call_user_func_array(array($this->pdo, $name), $vars);
		else return false;
	}
}
